package com.dzh.controller;

import com.dzh.mapper.AgentMapper;
import com.dzh.mapper.GalleyMapper;
import com.dzh.pojo.Agent;
import com.dzh.pojo.Galley;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
public class AgentController {
    @Autowired
    private AgentMapper agentMapper;
    @Autowired
    private GalleyMapper galleyMapper;




    @RequestMapping("/toagentdetail")
    public String agentdetail(Integer agentid, Model model){
        List<Galley> list_new =new ArrayList<Galley>();

        Agent agent =   agentMapper.queryAgentByAid(agentid);
        List<Integer> pidlist = galleyMapper.queryPidByAid(agentid);
        for (Integer pid : pidlist){
        Galley galley =  galleyMapper.queryGalleyById(pid);
        list_new.add(galley);
        }
        agent.setGalleyList(list_new);


      model.addAttribute("agent",agent);
      return "agent-detail";
    }


    @RequestMapping("/agent")
    public String agent(Model model){
      List<Agent> agentlist =  agentMapper.queryAllAgent();
      model.addAttribute("agentlist",agentlist);
        return "agents";
    }


    @RequestMapping("/agentservices")
    public String agentlist(Model model){
        List<Agent> agentlist =  agentMapper.queryAllAgent();
        model.addAttribute("agentlist",agentlist);
        System.out.println(agentlist);
        return "services";
    }




}
